package cn.spring.service.impl;

import cn.spring.dao.UserDao;
import cn.spring.dao.factory.UserDaoFactory;
import cn.spring.dao.impl.UserDaoImpl;
import cn.spring.pojo.User;
import cn.spring.service.UserService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


public class UserServiceImpl implements UserService {

//    @Resource(name = "userDao")
//    @Resource
    //实例化所依赖的UserDao

    private UserDao dao;
    public UserDao getDao() {
        return dao;
    }

    public void setDao(UserDao dao) {
        this.dao = dao;
    }

    public UserDao getDoaTow() {
        return doaTow;
    }

    public void setDoaTow(UserDao doaTow) {
        this.doaTow = doaTow;
    }

    public void addNewUser(User user){
        dao.save(user);
    }

    //通过工厂获取所依赖的用户DAO对象
    private UserDao doaTow = UserDaoFactory.getInstance();
    public void addNewUserTow(User user){
        doaTow.save(user);
    }

    //第六章示例一
    //声明接口类型的引用和具体实现类解耦合


    public UserServiceImpl(){

    }

    public UserServiceImpl(UserDao dao){
        this.dao = dao;
    }

    public void setDao(UserDaoImpl dao) {

    }
}
